{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# A structured self-attentive sentence embedding\n",
    "\n",
    "The goal is to implement the architecture of the [paper](https://arxiv.org/abs/1703.03130)\n",
    "\n",
    "We will start from the [implementation of Freda Shi](https://github.com/ExplorerFreda/Structured-Self-Attentive-Sentence-Embedding)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## obtaining GloVe model in PyTorch\n",
    "\n",
    "We will use [torchtext](https://github.com/pytorch/text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torchtext import data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 398686/400000 [00:17<00:00, 21779.03it/s]"
     ]
    }
   ],
   "source": [
    "from torchtext import vocab\n",
    "# specify the path to the localy saved vectors\n",
    "# better results with glove.42B.300d.txt\n",
    "vec = vocab.Vectors('glove.6B.200d.txt', '/home/public/glove/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "vectors = torch.load('/home/public/glove/glove.6B.200d.txt.pt')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note a first difference with the code of Freda Shi..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(vectors)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Yelp dataset\n",
    "\n",
    "If you want to have the full dataset you can dowload it from [here](https://www.yelp.com/dataset), then you will need to tokenize it.\n",
    "\n",
    "A small version is available on my [webpage](https://www.di.ens.fr/~lelarge/small_yelp.zip)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# play with the model..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
